//
//  HSYRootTabBarController.m
//  HSY
//
//  Created by 陈浩 on 2017/4/1.
//  Copyright © 2017年 金开门. All rights reserved.
//

#import "HSYRootTabBarController.h"
#import "HSYHomeViewController.h"
#import "HSYMineViewController.h"
#import "HSYLoginViewController.h"

@interface HSYRootTabBarController ()<UITabBarControllerDelegate>

@end

@implementation HSYRootTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:RGBA(81, 94, 149, 1), NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:RGBA(81, 94, 149, 1), NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    self.delegate = self;
    
    [self setupViewControllers];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setupViewControllers{
    HSYHomeViewController *homeViewController = [[HSYHomeViewController alloc] init]; //首页
    HSYMineViewController *mineViewController = [[HSYMineViewController alloc] init]; //我的
    
    UIImage *homeDefaultImage = [UIImage imageNamed:@"home"];
    UIImage *homeSelectedImage = [UIImage imageNamed:@"home_click"];
    
    UIImage *mineDefaultImage = [UIImage imageNamed:@"mine"];
    UIImage *mineSelectedImage = [UIImage imageNamed:@"mine_click"];


    [self addChildViewController:homeViewController image:homeDefaultImage selectedImage:homeSelectedImage title:@"首页" inNavigationCongroller:YES];
    [self addChildViewController:mineViewController image:mineDefaultImage selectedImage:mineSelectedImage title:@"我的" inNavigationCongroller:YES];
}

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    if ([tabBarController.childViewControllers indexOfObject:viewController] ==1) {
        if (![HSYUserCenter instatce].appAuUser.uid) {
            HSYLoginViewController *vc = [[HSYLoginViewController alloc] init];
            HSYBaseNavigationController *nav = [HSYBaseNavigationController navigtationControllerWithRootViewController:vc];
            nav.hidesBottomBarWhenPushed = YES;
            
            [self presentViewController:nav animated:YES completion:nil];
            
            return NO;
        }
    }
    
    return YES;
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
